package com.ywk.effective;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BiConsumer;

/**
 * Copyright (C) 2023 思创数码科技股份有限公司
 * <p/>
 * 版权所有
 * <p/>
 * 类名　　  : DeadLock
 * 功能概要  :
 *
 * @Author : yangwk
 * @Date : 2024/3/25 23:24
 */
public class DeadLock {
    private static byte[] arr = new byte[0];

    public static void get(BiConsumer functionalInterface) {
        synchronized (arr) {
            System.out.println(1);
        }
        functionalInterface.accept(1 , 1);
    }
    public static void remove() {
        synchronized (arr) {
            System.out.println(2);
        }
    }

    public static void main(String[] args) {
        get((o, o2) -> {
            ExecutorService executorService = Executors.newSingleThreadExecutor();
            try {
                executorService.submit(() -> remove()).get();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        });
    }
}
